package com.jic.veteran.component;

import com.jic.veteran.bo.AdminUserDetails;
import com.jic.veteran.model.UmsAdmin;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class VeteranSecurityContext {
    public static <T extends AdminUserDetails> T getUser() {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();

        if (auth != null && auth.getPrincipal() instanceof UserDetails) {
            return ((T) auth.getPrincipal());
        }
        return null;
    }

    public static String getUserName() {
        String userName = getUser().getUsername();
        if (userName != null) {
            return userName;
        }
        return null;
    }
}
